package site.guns.util;


import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.config.Scope;

public class SimpleMapScope implements Scope {
    private final Map<String , Object> objectMap = new HashMap<>();

    @Override
    public Object get(final String theName, final ObjectFactory<?> theObjectFactory) {
        Object object = objectMap.get(theName);
        if (null == object) {
            object = theObjectFactory.getObject();
            objectMap.put(theName, object);
        }
        return object;
    }

    @Override
    public String getConversationId() {
        return null;
    }

    @Override
    public void registerDestructionCallback(final String theName, final Runnable theCallback) {
        //empty
    }

    @Override
    public Object remove(final String theName) {
        return objectMap.remove(theName);
    }

    @Override
    public Object resolveContextualObject(String string) {
        return null;
    }
}
